datepicker = {}

datepicker.init = function(){
    var datepicker = $('.datepicker');
    datepicker.datetimepicker({ 
        showOn: "button",
        buttonImage: fly.assetsUrl + "/images/icon-calendar.png",
        buttonImageOnly: true,
        dateFormat: 'dd/mm/yy'
    });
    $( ".datepicker" ).each(function(){
        $(this).after('<input type="text" id="_'+$(this).attr('id')+'" style="width:'+$(this).css('width')+'"/>');
        if($(this).val() != ''){
            var dd = new Date(parseInt($(this).val()*1000));
            $('#_'+$(this).attr('id')).val(dd.getDate()+'/'+(dd.getMonth()+1)+'/'+dd.getFullYear()+' '+dd.getHours()+":"+dd.getMinutes());
        }
        $(this).change(function(){
            $('#_'+$(this).attr('id')).val($(this).val());
            if($(this).val() != null){
                var mm = $(this).val().split(' ');
                var dd = mm[0].split('/');
                if(mm[1])
                    var hh = mm[1].split(':');
                var date = new Date();
                date.setFullYear(dd[2]);
                date.setMonth(dd[1]-1);
                date.setDate(dd[0]);
                if(mm[1])
                    date.setHours(hh[0], hh[1], 0, 0);
                $(this).val(parseInt(date.getTime()/1000));
            }
        });
        var input = $(this);
        $('#_'+$(this).attr('id')).change(function(){
            var mm = $(this).val().split(' ');
            var dd = mm[0].split('/');
            if(mm[1])
				var hh = mm[1].split(':');
            var date = new Date();
            date.setFullYear(dd[2]);
            date.setMonth(dd[1]-1);
            date.setDate(dd[0]);
            date.setHours(hh[0], hh[1], 0, 0);
            input.val(date.getTime()/1000);
        });
    });
}